using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using NazSoft.Framework;
using System.Linq;
using System.Transactions;
using Nazsoft.Entity;

namespace Nazsoft.DAL
{
    public class tblUserRightsDAL
    {

        #region Constructor
        public tblUserRightsDAL()
        { }
        #endregion

        #region Public Methods
        public int Save(tblUserRights Tbluserrights)
        {
            SqlHelper helper = new SqlHelper();
            int id = 0;

            Tbluserrights.CreatedBy = SessionHandler.UserInfo.Username;

            Tbluserrights.CreatedDate = DateTime.Now;

            Tbluserrights.UpdatedBy = SessionHandler.UserInfo.Username;

            Tbluserrights.UpdatedDate = DateTime.Now;

            using (TransactionScope t = new TransactionScope(TransactionScopeOption.Suppress))
            {

                if (Tbluserrights.Id == 0 || Tbluserrights.Id == null)


                    id = helper.OperationEntity("tblUserRights_Insert", Tbluserrights, OperationMode.Add, "Id");
                else

                    id = helper.OperationEntity("tblUserRights_Update", Tbluserrights, OperationMode.Edit, "");
                t.Complete();

            }

            CacheHelper.ClearAll();

            return id;
        }
        
        public int Delete(tblUserRights Tbluserrights)
        {
            SqlHelper helper = new SqlHelper();
            int id = 0;

            Tbluserrights.CreatedBy = SessionHandler.UserInfo.Username;

            Tbluserrights.CreatedDate = DateTime.Now;

            Tbluserrights.UpdatedBy = SessionHandler.UserInfo.Username;

            Tbluserrights.UpdatedDate = DateTime.Now;

            using (TransactionScope t = new TransactionScope(TransactionScopeOption.Suppress))
            {
                id = helper.OperationEntity("tblUserRights_Delete", Tbluserrights, OperationMode.Delete, "");
                t.Complete();

            }

            CacheHelper.ClearAll();

            return id;
        }

        #endregion

    }
}
